package com.kolaxy.ribbonconsumer;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.command.AsyncResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

/**
 * <一句话功能描述><功能详细描述>
 *
 * @author zhourunjin
 * @version: [版本号，2018-09-05]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class UserService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand
    public String getUserById(Long id){
        return restTemplate.getForObject("http://hello-service/hello?user/{1}",String.class,1);
    }

    @HystrixCommand()
    public AsyncResult<Object> getUserByIdAsync(final String id){

        return new AsyncResult<Object>(){
            @Override
            public String invoke() {
                return restTemplate.getForObject("http://hello-service/hello?user/{1}",String.class,1);
            }
        };
    }
}
